//
//  TTICommonUtils.m
//  DanoneEA
//
//  Created by Senela on 16/9/23.
//  Copyright © 2016年 翔傲科技. All rights reserved.
//

#import "TTICommonUtils.h"
#import "AppMacro.h"


//定义导航视图
void NAV_INIT(UIViewController *vc ,NSString *title, id left ,SEL leftObj, id right, SEL rightObj)
{ 
    if(left != nil){
        if([left isKindOfClass:[UIImage class]])
        {
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 8, 20, 30)];
            UIImageView *leftImgView = [[UIImageView alloc] initWithFrame:CGRectMake(3, 4, 10, 20)];
            leftImgView.image = (UIImage *)left;
            [button addSubview:leftImgView];
            [button addTarget:vc.self action:leftObj forControlEvents:UIControlEventTouchUpInside];
            UIBarButtonItem *leftBarBtnItem = [[UIBarButtonItem alloc] initWithCustomView:button];
            vc.navigationItem.leftBarButtonItem = leftBarBtnItem;
        }
        else if ([left isKindOfClass:[NSString class]])
        {
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 80, 20)];
            UILabel *titleTxt = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 20)];
            titleTxt.text = left;
            [titleTxt setFont:FontSize_Button];
            titleTxt.textColor = NavTitle_TextColor;
            titleTxt.textAlignment = NSTextAlignmentLeft;
            [button addSubview:titleTxt];
            
            [button addTarget:vc.self action:leftObj forControlEvents:UIControlEventTouchUpInside];
            
            [titleTxt setBackgroundColor:[UIColor clearColor]];
            [button setBackgroundColor:[UIColor clearColor]];
            UIBarButtonItem *leftBarBtnItem = [[UIBarButtonItem alloc] initWithCustomView:button];
            vc.navigationItem.leftBarButtonItem = leftBarBtnItem;
        }
    }
    else
        vc.navigationItem.leftBarButtonItem = nil;
    
    if(right != nil){
        if([right isKindOfClass:[UIImage class]])
        {
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(220, 10, 44, 44)];
            UIImage *image = (UIImage *)right;
            CGFloat size = image.size.width > image.size.height ? image.size.width : image.size.height;
            size = size>44 ? 44 : size;
            
            UIImageView *rightImgView = [[UIImageView alloc] initWithFrame:CGRectMake((44-size)/2, (44-size)/2, size, size)];
            rightImgView.contentMode = UIViewContentModeCenter;
            rightImgView.image = image;
            
            [button addSubview:rightImgView];
            [button addTarget:vc.self action:rightObj forControlEvents:UIControlEventTouchUpInside];
            
            [button setBackgroundColor:[UIColor clearColor]];
            UIBarButtonItem *rightBtnItem = [[UIBarButtonItem alloc] initWithCustomView:button];
            vc.navigationItem.rightBarButtonItem = rightBtnItem;
        }
        else if ([right isKindOfClass:[NSString class]])
        {
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 80, 20)];
            UILabel *titleTxt = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 20)];
            titleTxt.text = right;
            [titleTxt setFont:FontSize_Button];
            titleTxt.textColor = NavTitle_TextColor;
            titleTxt.textAlignment = NSTextAlignmentRight;
            [button addSubview:titleTxt];
            [button addTarget:vc.self action:rightObj forControlEvents:UIControlEventTouchUpInside];
            
            [titleTxt setBackgroundColor:[UIColor clearColor]];
            [button setBackgroundColor:[UIColor clearColor]];
            UIBarButtonItem *rightBtnItem = [[UIBarButtonItem alloc] initWithCustomView:button];
            vc.navigationItem.rightBarButtonItem = rightBtnItem;
        }
    }
    else
        vc.navigationItem.rightBarButtonItem = nil;
    
    if(title != nil){
        UILabel *titleView = [[UILabel alloc] initWithFrame:CGRectMake(110, 8, 100, 25)];
        titleView.text = title;
        [titleView setFont:FontSize_NavTitle];
        [titleView setTextColor:NavTitle_TextColor];
        titleView.textAlignment = NSTextAlignmentCenter;
        [titleView setBackgroundColor:[UIColor clearColor]];
        vc.navigationItem.titleView = titleView;
    }
    
}




 
@implementation TTICommonUtils

@end
